package ygw.study.designPatterns.chain;

/**
 * <p>
 * 设计模式-责任链
 * </p>
 * <p>
 * Copyright:2021.All rights reserved.
 * </p>
 * <p>
 * Company:Zsoft
 * </p>
 * <p>
 * CreateDate:2021-05-18 15:58
 * </p>
 *
 * @author YuGongWen
 * @history Mender:YuGongWen；Date:2021-05-18 15:58；
 */
public class TestChain {

    private static AbstractLogger getChainOfLoggers() {

        AbstractLogger errorLogger = new ErrorLogger(AbstractLogger.ERROR);
        AbstractLogger fileLogger = new FileLogger(AbstractLogger.DEBUG);
        AbstractLogger consoleLogger = new ConsoleLogger(AbstractLogger.INFO);

        errorLogger.setNextLogger(fileLogger);
        fileLogger.setNextLogger(consoleLogger);

        return errorLogger;
    }

    public static void main(String[] args) {
        AbstractLogger loggerChain = getChainOfLoggers();

        loggerChain.logMessage(AbstractLogger.INFO, "This is an information.");

        loggerChain.logMessage(AbstractLogger.DEBUG,"This is a debug level information.");

        loggerChain.logMessage(AbstractLogger.ERROR,"This is an error information.");
    }
}